class ImageResizeWorker < BackgrounDRb::MetaWorker
  set_worker_name :image_resize_worker

  def create(args = nil)
    #called when the worker is loaded
  end

  def do_work args
    # This method is called in it's own new thread when you
    # call new worker. args is set to :args
    logger.info("starting resizing")
    image_file = args[:absolute_path]
    logger.info("File: " + image_file)
    id = args[:image_id]
    logger.info("Image id: " + id)
    image = ImageFile.find(id.to_i)
    image.attachment_options[:resize_to] = '2500x2000>'
    image.attachment_options[:thumbnails] = { :thumb => '200x200>', :medium => '600x600>', :large => '1024x768>' }
    if image.save
      image.media.upload_complete = 1
      image.media.save
    else
      logger.info(image.errors.inspect)
    end
    logger.info("done worker code")
    exit 1
  end
end
